package com.example.demo.commom;

import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2024-05-10
 * Time:14:59
 */
@Data
public class AjaxResult {
    private int code;//状态码 - 200响应正确 - -1有误 - 500-服务器内部出错  -1000-参数有误 1001-用户名或密码错误-1002用户已被注册 - 1003无权限操作 - 1004数据不存在
    private String msg;//错误信息
    private String data;//数据

    public static AjaxResult success(String data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setData(data);
        ajaxResult.setMsg("ok");
        return ajaxResult;
    }
    public static AjaxResult fail(String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(-1);
        ajaxResult.setData("");
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }
    public static AjaxResult fail(Integer code){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setData("");
        ajaxResult.setMsg("有误");
        return ajaxResult;
    }
    public static AjaxResult fail(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(500);
        ajaxResult.setData("");
        ajaxResult.setMsg("服务器内部错误");
        return ajaxResult;
    }
}
